/* This file is part of xREL
 *
 * Copyright (C) 2012 Timo Zimmermann <xrel@timozimmermann.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

import QtQuick 1.1
import com.xrel 1.0
import "../components"

Item {
    id: root
    width: parent.width - 12
    anchors.horizontalCenter: parent.horizontalCenter
    height: infoImage.height + listView.height

    ListItemHighlight { id: highlight }

    Image {
        id: infoImage
        anchors.left: parent.left
        anchors.leftMargin: 6
        height: 80
        width: height
        fillMode: Image.PreserveAspectFit
        source: cover_url
    }

    Label {
        id: label
        anchors.left: infoImage.right
        anchors.leftMargin: 6
        anchors.top: parent.top
        anchors.topMargin: 6
        text: title
        font.pixelSize: 26
    }

    Label {
        anchors.left: infoImage.right
        anchors.leftMargin: 6
        anchors.top: label.bottom
        anchors.topMargin: 6
        text: genre
        font.pixelSize: 20
    }

    CountBubble {
        anchors.right: parent.right
        anchors.rightMargin: 6
        anchors.verticalCenter: infoImage.verticalCenter
        value: unreadReleasesListModel.count
    }

    MouseArea {
        anchors.fill: parent
        onPressed: highlight.opacity = 1.0
        onReleased: highlight.opacity = 0.0
        onPositionChanged: highlight.opacity = 0.0
        onClicked: parent.ListView.view.showProductInfo(id)
    }

    XmlListModel {
        id: unreadReleasesListModel

        xml: root.ListView.view.model.xml
        query: "/fav_list_entries/ext_info[" + (index+1) + "]/releases/release"

        XmlRole { name: "id"; query: "id/string()" }
        XmlRole { name: "dirname"; query: "dirname/string()" }
        XmlRole { name: "link_href"; query: "link_href/string()" }
        XmlRole { name: "time"; query: "time/string()" }
    }

    ListView {
        id: listView
        anchors.top: infoImage.bottom
        anchors.left: infoImage.right
        width: parent.width - infoImage.width
        interactive: false
        cacheBuffer: 1

        delegate: ReleaseSceneSmallDelegate { }
        model: unreadReleasesListModel

        function showReleaseSceneInfo(id) {
            pageStack.push(Qt.resolvedUrl("../ReleaseSceneInfoPage.qml"), { id: id })
        }
    }
}
